package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbItemMapper;
import com.dongdongshop.pojo.TbItem;
import com.dongdongshop.pojo.TbItemExample;
import com.dongdongshop.service.TbItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class TbItemServiceImpl implements TbItemService {
    @Autowired
    private TbItemMapper tbItemMapper;
    @Override
    public List<TbItem> selectByGoodsId(Long goodsId) {
        //参数是普通的字段不能用自带的查询
        //查询sku列表数据
        TbItemExample example = new TbItemExample();
        TbItemExample.Criteria criteria = example.createCriteria();
        //状态为正常的"1"
        criteria.andStatusEqualTo("1");
        //剩余库存大于0的
        criteria.andNumGreaterThan(0);
        //goodsId为传入的商品图片
        criteria.andGoodsIdEqualTo(goodsId);
        example.setOrderByClause("is_default desc");
        return tbItemMapper.selectByExample(example);
    }

    @Override
    public TbItem selectByItemId(Long itemId) {
        TbItem tbItem = tbItemMapper.selectByPrimaryKey(itemId);
        return tbItem;
    }
}
